package scau.erps.view.base;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import scau.erps.app.Erps;
import scau.erps.entity.Sand;
import scau.erps.entity.TeamOrder;
import scau.erps.service.SandService;
import scau.erps.service.TeamOrderService;
import scau.erps.service.impl.SandServiceImpl;
import scau.erps.service.impl.TeamOrderServiceImpl;

/**
 * 交货界面对话框
 * @author FYJ
 *
 */
public class DeliveryDialog extends JDialog{
	private static final long serialVersionUID = 1L;
	private JButton exitButton;
	public DeliveryDialog(final DecisionPanel superPanel){
		setTitle("订单交货");
		setSize(1024, 450);
		setDefaultCloseOperation(0);
		setResizable(false);
		setLocationRelativeTo(null);
		JPanel contentPanel = new JPanel();
		DeliveryPanel deliveryPanel = new DeliveryPanel(superPanel);
		exitButton = new JButton("退出");
		exitButton.setBounds(900, 400, 78, 23);
		exitButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int team_Id=Erps.getCurrentTeam().getId();
				int flag = 0;
				SandService sandService = Erps.getIocInstance().get(SandServiceImpl.class);
				TeamOrderService teamOrderService = Erps.getIocInstance().get(TeamOrderServiceImpl.class);
				Sand sand = sandService.getSandByTeam(team_Id);
				List<TeamOrder> list = teamOrderService.getTeamOrderByDeliverTime(team_Id, sand.getTime());
				for(TeamOrder teamOrder:list){
					if(teamOrder.getStatus().equals("未交货")) flag += 1;
				}
				if(sand.getCash()>0){
					if(flag==0)
						{  
						    superPanel.getDashBoardPanel().setReceivableData();    
						    dispose();		    
						}
					else
						JOptionPane.showMessageDialog(null, "有未处理订单，请及时处理", "提示", JOptionPane.INFORMATION_MESSAGE);
				}else{
					JOptionPane.showMessageDialog(null, "已破产，请申请高利贷", "提示", JOptionPane.INFORMATION_MESSAGE);
				}
				
			}
		});
		contentPanel.add(deliveryPanel);
		contentPanel.setBounds(47, 0, 930, 200);
		this.setContentPane(contentPanel);
		this.add(exitButton);
		this.setModal(true);
	}

}
